import random
from threading import Thread

result=[]
def compute():
    '''计算100万个1到100之间的随机数的和'''
    total = sum([random.randint(1,100) for i in range(1000000)])
    result.append(total)

def main():
    # 生成8个线程对象
    threads = [Thread(target=compute) for i in range(8)]
    # 启动多线程
    for thread in threads:
        thread.start()
        # 主线程等待所有子线程执行完
    for thread in threads:
         thread.join()

    # 多线程是共享进程里面的内存空间
    print(result)
if __name__ == '__main__':
    main()
